function formatTime(t) {
  var r = t.getFullYear(),
      e = t.getMonth() + 1,
      a = t.getDate(),
      o = t.getHours(),
      n = t.getMinutes(),
      m = t.getSeconds();
  return [r, e, a].map(formatNumber).join("/") + " " + [o, n, m].map(formatNumber).join(":");
}

function formatData(t) {
  var r = t.getFullYear(),
      e = t.getMonth() + 1,
      a = t.getDate();
  t.getHours(), t.getMinutes(), t.getSeconds();
  return [r, e, a].map(formatNumber).join("-");
}

function formatNumber(t) {
  return (t = t.toString())[1] ? t : "0" + t;
}

function objectToUrlParams(t) {
  var r = "";

  for (var e in t) r += "&" + e + "=" + t[e];

  return r.substr(1);
}

function onShareAppMessage(title, path, callback, imageUrl) {
  //设置一个默认分享背景图片
  let defaultImageUrl = '';
  return {
    title: title,
    path: path,
    imageUrl: imageUrl || defaultImageUrl,

    success(res) {
      console.log("转发成功！");

      if (!res.shareTickets) {
        //分享到个人
        api.shareFriend().then(() => {
          console.warn("shareFriendSuccess!"); //执行转发成功以后的回调函数

          callback && callback();
        });
      } else {
        //分享到群
        let st = res.shareTickets[0];
        wx.getShareInfo({
          shareTicket: st,

          success(res) {
            let iv = res.iv;
            let encryptedData = res.encryptedData;
            api.groupShare(encryptedData, iv).then(() => {
              console.warn("groupShareSuccess!"); //执行转发成功以后的回调函数

              callback && callback();
            });
          }

        });
      }
    },

    fail: function (res) {
      console.log("转发失败！");
    }
  };
}

module.exports = {
  formatTime: formatTime,
  onShareAppMessage: onShareAppMessage,
  objectToUrlParams: objectToUrlParams,
  formatData: formatData,
  scene_decode: function (t) {
    var r = (t + "").split(","),
        e = {};

    for (var a in r) {
      var o = r[a].split(":");
      0 < o.length && o[0] && (e[o[0]] = o[1] || null);
    }

    return e;
  }
};